package com.decade.service.impl;

import com.decade.mapper.GoodsMapper;
import com.decade.pojo.Goods;
import com.decade.service.GoodsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;
    private static final Logger log =
            LoggerFactory.getLogger(GoodsServiceImpl.class);
/**
 * 此对象负责商品
 * */
    @Override
    public List<Goods> findGoods() {
        try {
            long t1 = System.currentTimeMillis();
            log.info("start {}",t1);
            List<Goods> list = goodsMapper.findGoods();
            long t2 = System.currentTimeMillis();
            log.info("end {}",t2);
            log.info("执行时间 {}",t2-t1);
            return list;
        } catch (Exception e) {
            log.info("查询失败");
            e.printStackTrace();
        }
        log.info("查询失败");
        return null;
    }

    //删除
    @Override
    public int deleteById(Integer id) {
        if(id==null||id<1){
            //TODO问题如果每个方法都加入日志，这样写的代码量很大，以后用AOP思想解决
            log.info("参数不合法");
            throw new IllegalArgumentException("传入的值不合法");
        }
        return goodsMapper.deleteById(id);
    }

    //修改
    @Override
    public int updateById(Goods goods) {
        return goodsMapper.updateById(goods);
    }
}
